package com.dailyblue.java.io;

import java.io.*;
import java.util.Scanner;

// 文件输出流
public class DemoE {

    private static void a() throws IOException {
        File file = new File("D://a//a//a.txt");
        OutputStream out = new FileOutputStream(file, true);
        byte[] bytes = "\n你好，世界！\n".getBytes();
        out.write(bytes);
        out.close();
    }

    private static Scanner scan = new Scanner(System.in);

    private static void b() throws IOException {
        OutputStream out = new FileOutputStream("D://a//a//b.txt", true);
        while (true) {
            System.out.print("Input:");
            String str = scan.next() + "\n";
            if ("exit\n".equals(str)) {
                break;
            }
            out.write(str.getBytes());
        }
        out.close();
    }

    // 将D://1.jpg--->C://1.jpg 复制
    public static void c() throws IOException {
        long start = System.currentTimeMillis();
        // 代表要复制的内容
        File src = new File("D://a//a//变量和运算符.mp4");
        // 复制到哪里去
        File desc = new File("D://a//b//", src.getName());
        InputStream in = new FileInputStream(src);
        OutputStream out = new FileOutputStream(desc, true);
        byte[] bytes = new byte[100];
        while (true) {
            // 读取内容到bytes数组中
            int len = in.read(bytes);
            if (len == -1) {
                break;
            }
            // 将bytes数组的内容写入到文件中
            out.write(bytes, 0, len);
        }
        out.close();
        in.close();

        long end = System.currentTimeMillis();
        long time = (end - start) / 1000;
        System.out.println("一共花了：" + time + "秒，共：" + (end - start) + "毫秒！");
    }

    public static void main(String[] args) throws IOException {
        c();
    }
}
